local Bullet = {}
local t_concat = table.concat
local t_rm 	= table.remove
local t_sort = table.sort
local math_ceil = math.ceil

local bullet_mt = {__index = Bullet}

local bullet_type = {
	bullet_
}

local player_plane_size = {
	width = 186,
	height = 130,
}
 
 local enemy_plane_size = {
	width = 120,
	height = 79,
 }
 
 local bullet_size = {
	width = 62,
	height = 108,
 }

--[[
	type  0  玩家
		  1  敌人
]]

function Bullet:ctor(idx)
	self._idx = idx;
	self._posX = 0;
	self._posY = 0;
	self._speed = 0;
	self._width = 0;
	self._height = 0;
	self._angle = 90;
	self._ntype = 0;
	self._endposX = 0;
	self._endposY = 0;
	self._attack = 100;
	
	self._playerbulletindex = -1;
	self._enemybulletindex = -1;
	self._fitbulletindex = -1;
	
	self._actionarray = {};
	
	self._actionstep = 0;
	self._steptime = 0;
end

function Bullet:getInfo()
	return {
		idx = self._idx,
		posX = self._posX,
		posY = self._posY,
		speed = self._speed,
		width = self._width,
		height = self._height,
		angle = self._angle,
		ntype = self._ntype,
		endposX = self._endposX,
		endposY = self._endposY,
		attack = self._attack,
		playerindex = self._playerbulletindex,
		enemyindex = self._enemybulletindex,
		fitplayerindex = self._fitbulletindex,
	}
end

function Bullet:setBulletData(data)
	self._speed = data.speed or 0
	self._width = data.size.width or 0
	self._height = data.size.height or 0
	self._angle = data.angle or 0
end

function Bullet:setActionArray(action)
	self._actionarray = action or {}
end

function Bullet:getActionArray()
	return self._actionarray;
end

function Bullet:setPlayerBulletIdx(idx)
	self._playerbulletindex = idx;
end

function Bullet:getPlayerBulletIdx()
	return self._playerbulletindex;
end

function Bullet:setEnemyBulletIdx(idx)
	self._enemybulletindex = idx;
end

function Bullet:getEnemyBulletIdx()
	return self._enemybulletindex;
end

function Bullet:getFitBulletIdx()
	return self._fitbulletindex;
end

function Bullet:setFitBulletIdx(idx)
	self._fitbulletindex = idx;
end

function Bullet:setAngle(angle)
	self._angle = angle;
end

function Bullet:getAngle()
	return self._angle;
end

function Bullet:setType(ntype)
	self._ntype = ntype;
end

function Bullet:getType()
	return self._ntype;
end

function Bullet:setPositon(pos)
	self._posX = pos.x or 0;
	self._posY = pos.y or 0;
end

function Bullet:getPosition()
	return 
	{
		nXpos = self._posX, 
		nYpos = self._posY,
	};
end

function Bullet:setEndPositon(pos)
	self._endposX = pos.x or 0;
	self._endposY = pos.y or 0;
end

function Bullet:getEndPosition()
	return 
	{
		nXpos = self._endposX, 
		nYpos = self._endposY,
	};
end

function Bullet:setSpeed(speed)
	self._speed = speed;
end

function Bullet:getSpeed()
	return self._speed;
end

function Bullet:move()
	if self._angle == 90 then
		self._posY = self._posY + self._speed;
	elseif self._angle == -90 then
		self._posY = self._posY - self._speed;
	else
		self._posX = self._posX + Math.cos(self._angle / 180 * Math.PI) * self._speed;
		self._posY = self._posY + Math.sin(self._angle / 180 * Math.PI) * self._speed;	
	end
	
	self._actionstep = 1;
	self._steptime = self._steptime + 0.02
end

function Bullet:getActionStats()
	return { actionstep = self._actionstep, steptime = self._steptime }
end

function Bullet:judgeOut()
	if self._posX < -200 or self._posX > 900 or self._posY < -200 or self._posY > 1700 then
		self:destroy()
		return true;
	end
	return false;
end

function Bullet:destroy()
	
end

function Bullet.new(...)
	local instance = {}
	setmetatable(instance, bullet_mt)
	instance:ctor(...)
	return instance
end

return Bullet
